package org.zjvis.datascience.common.model;

import com.google.common.base.Joiner;
import lombok.Data;

import java.text.MessageFormat;

/**
 * @description SelectItem 聚合函数包装类
 * @date 2020-07-27
 */
@Data
public class FunctionConfig {

    private String name;

    private Object[] params;

    public FunctionConfig(String name, Object[] params) {
        this.name = name;
        this.params = params;
    }

    public String wrapFunc(){
        String paramsStr = '\'' + Joiner.on(",").join(this.getParams()) +'\'';
        return this.getName() + "({0}, \'" +paramsStr+"\')";
    }

    public static void main(String[] args) {
        FunctionConfig funConf = new FunctionConfig("pipeline.sys_func_format_time", new String[]{"%Y-%m-%d"});
        String s = funConf.wrapFunc();
        System.out.println(s);
//        System.out.println(String.format("pipeline.sys_func_format_time( %s,'%Y-%m-%d %H:%M:%S')", "aaron"));
        String msg = MessageFormat.format(s, new Object[]{"aaron"});
        System.out.println(msg);
    }

}
